<template>
    <div id="job-creat" class="w-h-100 pos-r flex-1 apply-container page-public-s" style="box-sizing: border-box;overflow:hidden;">
        <div class="w-h-100 ver-flex pos-a" style="box-sizing: border-box; padding: 6px;">
            <div v-if="$hasPer('JobCreat:excel')" style="box-sizing: border-box;">
                <el-card shadow="never" :body-style="{ paddingBottom: '0' }">
                    <el-form class="box-f" ref="queryForm" :inline="true">
                        <el-form-item>
                            <!-- <el-button v-if="$hasPer('JobCreat:add')" @click="nodeClick('')" icon="ele-Plus" type="primary"> 新增 </el-button> -->
                            <el-button v-if="$hasPer('JobCreat:excel')" @click="handleExport" icon="ele-Download"> 导出数据 </el-button>
                        </el-form-item>
                    </el-form>
                </el-card>
            </div>

            <div style="box-sizing: border-box;" class="flex-1 pos-r">
                <div class="pos-a w-h-100" style="box-sizing: border-box;">
                    <el-card class="box-card w-h-100" shadow="never" style="margin-top: 16px;">
                        <div style="" class="w-h-100 ver-flex">
                            <div class="flex-1 pos-r">
                                <div class="pos-a w-h-100">
                                    <el-table 
                                        ref="excelRef"
                                        :data="list" 
                                        class="w-h-100" 
                                        style="width: 100%" 
                                        border 
                                        v-loading="loading" 
                                        element-loading-background="rgba(0, 0, 0, 0.5)"
                                    >

                                        <el-table-column min-width="200" :show-overflow-tooltip="true" label="作业票据类型" align="center" fixed="left">
                                            <el-table-column :show-overflow-tooltip="true" min-width="200" align="center">
                                                <template #header>
                                                    <SearchModel typeId="s_JobType" typeVal="select" @searchHandel="searchHandel" :basicsInfo="basicsInfo" />
                                                </template>
                                                <template #default="scope">
                                                    <span v-if="scope.row.v_JobTypeName">{{ scope.row.v_JobTypeName }}</span>
                                                    <span v-else> - </span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>

                                        <el-table-column min-width="200" :show-overflow-tooltip="true" label="作业申请编号" prop="v_ApplyNO"  align="center" sortable>
                                            <el-table-column :show-overflow-tooltip="true" min-width="200" align="center">
                                                <template #header>
                                                    <SearchModel typeId="i_Apply" typeVal="input" @searchHandel="searchHandel" :basicsInfo="basicsInfo" />
                                                </template>
                                                <template #default="scope">
                                                    <span v-if="scope.row.v_ApplyNO">{{ scope.row.v_ApplyNO }}</span>
                                                    <span v-else> - </span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>

                                        <el-table-column min-width="200" :show-overflow-tooltip="true" label="作业单位"  align="center">
                                            <el-table-column :show-overflow-tooltip="true" min-width="200" align="center">
                                                <template #header>
                                                    <SearchModel typeId="s_Provider" typeVal="select" @searchHandel="searchHandel" :basicsInfo="basicsInfo" />
                                                </template>
                                                <template #default="scope">
                                                    <span v-if="scope.row.v_ProviderName">{{ scope.row.v_ProviderName }}</span>
                                                    <span v-else> - </span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>

                                        <el-table-column min-width="200" :show-overflow-tooltip="true" label="动工地点"  align="center">
                                            <el-table-column :show-overflow-tooltip="true" min-width="200" align="center">
                                                <template #header>
                                                    <SearchModel typeId="i_Address" typeVal="input" @searchHandel="searchHandel" :basicsInfo="basicsInfo" />
                                                </template>
                                                <template #default="scope">
                                                    <span v-if="scope.row.v_JobAddress">{{ scope.row.v_JobAddress }}</span>
                                                    <span v-else> - </span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>

                                        <el-table-column width="230" :show-overflow-tooltip="true" prop="d_IntendedStartTime" sortable label="动工开始日期"  align="center">
                                            <el-table-column :show-overflow-tooltip="true" width="230" align="center">
                                                <template #header>
                                                    <SearchModel typeId="d_Intended" typeVal="date" @searchHandel="searchHandel" :basicsInfo="basicsInfo" />
                                                </template>
                                                <template #default="scope">
                                                    <span v-if="scope.row.d_IntendedStartTime">{{ scope.row.d_IntendedStartTime.split(' ')[0] }}</span>
                                                    <span v-else>-</span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>

                                        <el-table-column width="230" :show-overflow-tooltip="true" prop="d_IntendedCompletionTime" sortable label="完工日期"  align="center">
                                            <el-table-column :show-overflow-tooltip="true" width="230" align="center">
                                                <template #header>
                                                    <SearchModel typeId="d_Completion" typeVal="date" @searchHandel="searchHandel" :basicsInfo="basicsInfo" />
                                                </template>
                                                <template #default="scope">
                                                    <span v-if="scope.row.d_IntendedCompletionTime">{{ scope.row.d_IntendedCompletionTime.split(' ')[0] }}</span>
                                                    <span v-else>-</span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>

                                        <el-table-column min-width="200" :show-overflow-tooltip="true" label="动工内容"  align="center">
                                            <el-table-column :show-overflow-tooltip="true" min-width="200" align="center">
                                                <template #header>
                                                    <SearchModel typeId="i_Content" typeVal="input" @searchHandel="searchHandel" :basicsInfo="basicsInfo" />
                                                </template>
                                                <template #default="scope">
                                                    <span v-if="scope.row.v_JobContent">{{ scope.row.v_JobContent }}</span>
                                                    <span v-else>-</span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>

                                        <el-table-column min-width="200" :show-overflow-tooltip="true" label="项目名称"  align="center">
                                            <el-table-column :show-overflow-tooltip="true" min-width="200" align="center">
                                                <template #header>
                                                    <SearchModel typeId="s_Project" typeVal="select" @searchHandel="searchHandel" :basicsInfo="basicsInfo" />
                                                </template>
                                                <template #default="scope">
                                                    <span v-if="scope.row.v_ProjectName">{{ scope.row.v_ProjectName }}</span>
                                                    <span v-else>-</span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>

                                        <el-table-column min-width="200" :show-overflow-tooltip="true" label="申请部门"  align="center">
                                            <el-table-column :show-overflow-tooltip="true" min-width="200" align="center">
                                                <template #header>
                                                    <SearchModel typeId="s_Dep" typeVal="cascader" @searchHandel="searchHandel" :basicsInfo="basicsInfo" />
                                                </template>
                                                <template #default="scope">
                                                    <span v-if="scope.row.v_OrgName">{{ scope.row.v_OrgName }}</span>
                                                    <span v-else>-</span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>

                                        <el-table-column min-width="200" :show-overflow-tooltip="true" label="申请人员"  align="center">
                                            <el-table-column :show-overflow-tooltip="true" min-width="200" align="center">
                                                <template #header>
                                                    <SearchModel typeId="s_Emp" typeVal="select" @searchHandel="searchHandel" :basicsInfo="basicsInfo" />
                                                </template>
                                                <template #default="scope">
                                                    <span v-if="scope.row.v_ApplyEmpName">{{ scope.row.v_ApplyEmpName }}</span>
                                                    <span v-else>-</span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>

                                        <el-table-column width="430" :show-overflow-tooltip="true" label="申请时间"  align="center">
                                            <el-table-column :show-overflow-tooltip="true" width="430" align="center">
                                                <template #header>
                                                    <SearchModel typeId="d_ApplyTime" typeVal="datetimerange" @searchHandel="searchHandel" :basicsInfo="basicsInfo" />
                                                </template>
                                                <template #default="scope">
                                                    <span v-if="scope.row.d_ApplyTime">{{ scope.row.d_ApplyTime }}</span>
                                                    <span v-else>-</span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>

                                        <el-table-column min-width="180" :show-overflow-tooltip="true" prop="createdTime" label="创建时间"  align="center" sortable>
                                            <template #default="scope">
                                                <span v-if="scope.row.createdTime">{{ scope.row.createdTime }}</span>
                                                <span v-else>-</span>
                                            </template>
                                        </el-table-column>

                                        <el-table-column min-width="180" :show-overflow-tooltip="true" prop="updatedTime" label="更新时间"  align="center" sortable>
                                            <template #default="scope">
                                                <span v-if="scope.row.updatedTime">{{ scope.row.updatedTime }}</span>
                                                <span v-else>-</span>
                                            </template>
                                        </el-table-column>

                                        <el-table-column width="200" label="操作" align="center" fixed="right">
                                            <el-table-column :show-overflow-tooltip="true" width="200" align="center">
                                                <template #header>
                                                    <el-button class="icon-e" @click='searchClick' icon="ele-Search" size="small" type="primary" text> 查询 </el-button>
                                                    <el-button class="icon-e clear-bg" style="background-color: transparent !important;" size="small" @click="resetClick" icon="ele-Refresh" text> 重置 </el-button>
                                                </template>
                                                <template #default="scope">
                                                    <el-button @click="detailHandle(scope.row.id)" class="icon-e" icon="ele-View" size="small" text type="success">作业票详情</el-button>
                                                    <!-- <template v-if="scope.row.n_FlowinstanceState === 0">
                                                        <el-button v-if="$hasPer('JobCreat:uploadFile')" @click="documentClick(scope.row)" class="icon-e" icon="ele-Edit" size="small" text type="primary">上传文档</el-button>
                                                        <el-button v-if="$hasPer('JobCreat:edit')" @click="nodeClick(scope.row)" class="icon-e" icon="ele-Edit" size="small" text type="primary">编辑</el-button>
                                                        <el-button v-if="$hasPer('JobCreat:del')" @click="deleteHandle(scope.row.id, getData)" class="icon-e" icon="ele-Delete" size="small" text type="danger">删除</el-button>
                                                        <el-button v-if="$hasPer('JobCreat:apply')" @click="funClick(scope.row,0,getData)" class="icon-e" icon="ele-Finished" size="small" text type="warning">发起作业申请</el-button>
                                                    </template>
                                                    <el-button v-if="scope.row.n_FlowinstanceState === 1 && $hasPer('JobCreat:recall')" @click="funClick(scope.row,1,getData)" class="icon-e" icon="ele-EditPen" size="small" text type="danger">撤回作业申请</el-button>
                                                    <el-button v-if="scope.row.n_FlowinstanceState === 2 || scope.row.n_FlowinstanceState === 3  || scope.row.n_FlowinstanceState === 4 || scope.row.n_FlowinstanceState === 5" class="icon-e" size="small" text type="warning">{{ scope.row.v_FlowinstanceStateName }}</el-button> -->
                                                </template>
                                            </el-table-column>
                                        </el-table-column>
                                    </el-table>
                                </div>
                            </div>
                            <div style="height: 30px;margin-top: 20px;" class="hr-flex-start">
								<el-pagination
									v-model:currentPage="pageNo"
									v-model:page-size="pageSize"
									:total="totalRows"
									:page-sizes="[10, 20, 50, 100]"
									small
									background
									@size-change="handleSizeChange"
									@current-change="handleCurrentChange"
									layout="total, sizes, prev, pager, next, jumper"
									class="w-h-100"
								/>
							</div>
                        </div>
                    </el-card>
                </div>
            </div>
        </div>
        <AddEditJobRequest
            :repairInfo="repairInfo"
            :isUseDialog="isUseDialog"
            @updateData="getData"
            @cancelUseClick="cancelUseClick"
            @controlUseClick="controlUseClick"
        />
        <!-- 文件上传 -->
        <uploadFile
            isAccept=""
            :fileInfo="fileInfo"
            :isUseDialog="fileDialog"
            @cancelFileClick="cancelFileClick"
            @controlFileClick="controlFileClick"
            @updateData="getData"
        ></uploadFile>
        <InitJob
            :exaUrl="exaUrl"
            tempId="SmsJobApply"
            :repairInfo="initInfo"
            :initDialog="initDialog"
            @updateData="getData"
            @cancelInitClick="cancelInitClick"
            @controlInitClick="controlInitClick"
        />
        <!-- 作业票详情 -->
        <JobSlipDetail 
            :repairInfo="jobInfo"
            :isUseDialog="isJobDialog"
            @cancelJobClick="cancelJobClick"
        />
    </div>
</template>
<script lang="ts">
import { defineComponent, ref, Ref, onMounted , reactive , toRaw , toRefs, onBeforeMount } from 'vue';
import getTableData from '/@/utils/getTableData';
import AddEditJobRequest from '../component/sms/add-edit-JobRequest.vue';
import InitJob from '../component/sms/init-job.vue';
import JobSlipDetail from '../component/sms/job-slip-detail.vue';
import { 
    SMSJOBApplyPage,
    SMSJOBApplyApplyRevocation,
    SMSJOBApplyDelete,
    SMSJOBApplyApplySubimt,
    ProviderGetList,
    projectList,
    SMSJOBApplyDetail,
} from '/@/api/centerControl/sms';
import { sysDictDataList , sysUserselectorV2 , sysFileInfoPage , sysOrgTree } from '/@/api/centerControl/pubilc';
import { ElMessageBox , ElMessage } from 'element-plus';
import uploadFile from '../component/uploadFile.vue';
import SearchModel from '../component/search-model.vue';
import DetailModel from '../component/detail-model.vue';
import { exportToExcel } from '/@/utils/exportToExcel';
import { useRoute } from 'vue-router';

export default defineComponent( {
    name: 'job-creat',
    components: { AddEditJobRequest , InitJob , uploadFile , SearchModel , JobSlipDetail },
    setup(props){
        const isUseDialog = ref(false); // 新增/编辑弹出框隐藏/显示
        const repairInfo = ref(); // 传递子组件数据
        const isHoldDialog = ref(false);
        const initInfo = ref();
        const initDialog = ref(false);
        const router = useRoute();
        const baseUrl = import.meta.env.VITE_API_URL as any;
        const ideView = import.meta.env.VITE_APP_API_VIEW_IDE;


        /*** 新增/编辑 */
        const nodeClick = (val: any) => {
            repairInfo.value = val === '' ? '' : JSON.stringify(val);
            isUseDialog.value = true;
        }

        /*** 发起/测回作业申请 */
        const funClick = (val: any, num: number, updateFun: Function) => {
            let res: any;
            if(num === 0){
                console.log('12')
                initInfo.value = JSON.stringify(val);
                initDialog.value = true;
            }else{
                ElMessageBox.confirm('是否撤回当前作业申请？','提示',
                    {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning',
                    }
                )
                .then(async() => {
                    let param = {id : val}
                    try {
                        res = await SMSJOBApplyApplyRevocation({ id: val.id });
                        if(res.success){
                            updateFun();
                        }
                    } catch (err) { return }
                })
                .catch(() => {
                    ElMessage({
                        type: 'info',
                        message: '已取消',
                    })
                })
            }
        }

        /*** 发起作业申请审批取消事件 */
        const cancelInitClick = () => {
            initDialog.value = false;
        }

        /*** 发起作业申请审批提交事件 */
        const controlInitClick = () => {
            initDialog.value = false;
        }

        /*** 作业申请取消事件 */
        const cancelUseClick = () => {
            isUseDialog.value = false;
        }

        /*** 作业申请提交事件 */
        const controlUseClick = () => {
            isUseDialog.value = false;
        }

        /*** 作业申请删除事件 */
        const deleteHandle = (val: number, updateFun: Function) => {
            ElMessageBox.confirm('请确定删除此条数据？','提示',
                {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                }
            )
            .then(async() => {
                let param = {id : val}
                try {
                    let res:any = await SMSJOBApplyDelete(param);
                    if(res.success){
                        updateFun()
                    }
                } catch (err) { return }
            })
            .catch(() => {
                ElMessage({
                    type: 'info',
                    message: '已取消',
                })
            })
        }

        /*** 文件上传类数据操作 */
        
        
        /*** ================================= 文档上传事件 ================================= */
        const fileInfo = ref();
        const fileDialog = ref(false);
        const documentClick = (val:any) => {
            val.sourceType = 10;
            val.sourceId = val.l_FileId;
            val.titleCon = '作业文件上传';
            fileInfo.value = JSON.stringify(val);
            fileDialog.value = true;
        }
        
        /*** 文件上传取消事件 */
        const cancelFileClick = () => {
            fileDialog.value = false;
        };

        /*** 文件上传提交事件 */
        const controlFileClick = () => {
            fileDialog.value = false;
        }
        /*** ================================= 文档上传事件 ================================= */

        /*** ================================= 详情类数据操作 =================================  */
        const jobInfo = ref('');
        const isJobDialog = ref(false);

        // 获取文件
        const getFileFuns = async (sourceId: number) => {
            let viewUrl: string = '';
            let param: any = {};
            param.PageNo = 1;
            param.PageSize = 99999;
            param.sourceId = sourceId;
            let res: any = await sysFileInfoPage(param);
            if(res.success) {
                let dataItem:any = res.data.rows;
                if(dataItem.length !== 0){
                    dataItem.map((item: any) => {
                        viewUrl = baseUrl + 'api/Upload' + ideView + item.fileObjectName;
                    })
                }
            }
            return viewUrl;
        }

        /*** 获取详情接口数据 */
        const getDetailFun = async (id: number) => {
            let res: any = await SMSJOBApplyDetail({id: id}); // 详情
            if(res.success){
                console.log(res.data,'res.data')
                let getDataInfo: any = res.data;
                
                // 编制人
                if(getDataInfo.l_SafetyPreSingFileId && getDataInfo.l_SafetyPreSingFileId !== ''){
                    await getFileFuns(getDataInfo.l_SafetyPreSingFileId).then(async(res: any) => {
                        getDataInfo.v_SafetyPreSingFilePath = res;
                    });
                }
                // 接受交底人
                if(getDataInfo.acceptConfessions.length !== 0){
                    getDataInfo.acceptConfessions.map(async(item: any) => {
                        await getFileFuns(item.l_AcceptConfessionSingFileId).then((res: any) => {
                            item.v_AcceptConfessionSingFilePath = res;
                        });
                    });
                }
                // 签字
                if(getDataInfo.jobApplyChecks.length !== 0){
                    getDataInfo.jobApplyChecks.map(async(item: any) => {
                        await getFileFuns(item.l_AuditorSingFileId).then((res: any) => {
                            item.v_AuditorSingFilePath = res;
                        });
                    });
                }
                // 完工验收签字
                if(getDataInfo.l_AcceptorSingFileId && getDataInfo.l_AcceptorSingFileId !== ''){
                    await getFileFuns(getDataInfo.l_AcceptorSingFileId).then((res: any) => {
                        getDataInfo.v_AcceptorSingFilePath = res;
                    });
                }
                jobInfo.value = JSON.stringify(res.data);
                isJobDialog.value = true;
            }
        }
        /*** 详情 */
        const detailHandle = (id: number) => {
            getDetailFun(id);
        }

        /*** 作业票详情关闭事件 */
        const cancelJobClick = () => {
            isJobDialog.value = false;
        }
        /*** ================================= 详情类数据操作 =================================  */
        
        /*** ================================= 查询类数据操作 =================================  */
        let searchObj:any = reactive({
            IsContainNullEndDate: true,
            // id: router.query.queryParam ? router.query.queryParam : null,
        });
        const basicsInfo: any = ref([]);
        const searInfo: any = ref();

        /*** 获取需要查询的数据 */
        const searchHandel = (val: any) => {
            searInfo.value = val;
        }

        /*** 合法性判断 */
        const legalFun = async (valOne: any, valTwo: any, hintTitle: string, hintInfo: string) => {
            let isLegal = true;
            if(valTwo && !valOne){
                ElMessage({
                    type: 'error',
                    message: hintTitle,
                });
                isLegal = false;
            }
            if(valOne && valTwo){
                const dateMin = new Date(valOne).getTime();
                const dateMax = new Date(valTwo).getTime();
                console.log(dateMin,dateMax,'dateMax')
                if(dateMin >= dateMax){
                    ElMessage({
                        type: 'error',
                        message: hintInfo,
                    });
                    isLegal = false;
                }
            }
            return isLegal;
        }

        /*** 查询按钮 */
        const searchClick = async () => {
            let isLegal = true;
            if(searInfo.value.d_IntendedCompletionTimeMax){
                isLegal = await legalFun(
                    searInfo.value.d_IntendedStartTimeMin, 
                    searInfo.value.d_IntendedCompletionTimeMax, 
                    '请选择计划动工开始日期',
                    '计划动工开始日期不能大于或等于计划完工日期'
                ); 
            }
            if(!isLegal) return;

            let newObj = Object.keys(searInfo.value);
            if(newObj.length !== 0){
                newObj.map((i:any) => {
                    searchObj[i] = searInfo.value[i];
                });
            }
        };

        /*** 重置按钮 */
        const resetClick = () => {
            searInfo.value = {};
            let newObj = Object.keys(searchObj);
            if(newObj.length !== 0){
                newObj.map((i:any) => {
                    searchObj[i] = ''
                });
            }
            searchObj.IsContainNullEndDate = true;
            initInfoFun();
        };

        let jobArr: any = [];
        let providerArr: any = [];
        let projectArr: any = [];
        let empArr: any = [];
        let depArr: any = [];
        // 获取数据
        const getFun = async () => {
            // let ras: any = await sysDictDataList({ TypeCode: 'JobType' }); // 作业类型
            let rbs: any = await ProviderGetList({}); // 承包商
            let rcs: any = await projectList({}); // 项目
            let rds: any = await sysUserselectorV2({}); // 用户
            let res: any = await sysOrgTree({}); // 获取组织架构列表
            if(res.success && res.data.length !== 0) {
                depArr = res.data;
            }
            // if(ras.success && ras.data.length !== 0){
            //     console.log(ras.data,'ras.data')
            //     ras.data.map((item: any) => {
            //         item.label = item.value;
            //         item.value = item.value;
            //     });
            //     jobArr = ras.data;
            // }
            if(rbs.success && rbs.data.length !== 0){
                rbs.data.map((item: any) => {
                    item.label = item.v_ProvideName;
                    item.value = item.n_Id;
                });
                providerArr = rbs.data;
            }
            if(rcs.success && rcs.data.length !== 0){
                console.log(rcs,'rcs')
                rcs.data.map((item: any) => {
                    item.label = item.project_Name;
                    item.value = item.n_Id;
                });
                projectArr = rcs.data;
            }
            if(rds.success && rds.data.length !== 0){
                rds.data.map((item: any) => {
                    item.label = item.name;
                    item.value = item.id;
                });
                empArr = rds.data;
            }
        }
        
        /*** 初始化数据 */
        const initInfoFun = async() => {
            basicsInfo.value = [{
                    typeId: 's_JobType', // 类型(不能为空，且唯一，与组件中typeId值对应) --- 必填
                    typeNam: '', // 输入类型(number,text等) --- 选填
                    searchVal: 'n_JobType', // 查询字段 --- 必填
                    defaultVal: '', // 字段默认值 --- 选填
                    placeholder: '作业类型', // placeholder数据
                    defaultProp: [
                        {label: '动火',value: 0},
                        {label: '临时用电',value: 1},
                    ], // 下拉框中使用，除下拉框外其它情况为空 --- 选填
                    eventType: '', // 事件类型（如burl/change等） --- 选填
                    defaultEvent: '', // 事件名称 --- 选填
                },{
                    typeId: 'd_ApplyTime', // 类型(不能为空，且唯一，与组件中typeId值对应) --- 必填
                    typeNam: '', // 输入类型(number,text等) --- 选填
                    searchValMin: 'd_ApplyTimeMin', // 查询字段 --- 必填
                    searchValMax: 'd_ApplyTimeMax', // 查询字段 --- 必填
                    defaultVal: '', // 字段默认值 --- 选填
                    placeholder: '申请时间', // placeholder数据
                    defaultProp: '', // 下拉框中使用，除下拉框外其它情况为空 --- 选填
                    eventType: '', // 事件类型（如burl/change等） --- 选填
                    defaultEvent: '', // 事件名称 --- 选填
                },{
                    typeId: 's_Provider', // 类型(不能为空，且唯一，与组件中typeId值对应) --- 必填
                    typeNam: '', // 输入类型(number,text等) --- 选填
                    searchVal: 'l_ProviderId', // 查询字段 --- 必填
                    defaultVal: '', // 字段默认值 --- 选填
                    placeholder: '作业单位', // placeholder数据
                    defaultProp: providerArr, // 下拉框中使用，除下拉框外其它情况为空 --- 选填
                    eventType: '', // 事件类型（如burl/change等） --- 选填
                    defaultEvent: '', // 事件名称 --- 选填
                },{
                    typeId: 'i_Address', // 类型(不能为空，且唯一，与组件中typeId值对应) --- 必填
                    typeNam: '', // 输入类型(number,text等) --- 选填
                    searchVal: 'v_JobAddress', // 查询字段 --- 必填
                    defaultVal: '', // 字段默认值 --- 选填
                    placeholder: '动工地点', // placeholder数据
                    defaultProp: '', // 下拉框中使用，除下拉框外其它情况为空 --- 选填
                    eventType: '', // 事件类型（如burl/change等） --- 选填
                    defaultEvent: '', // 事件名称 --- 选填
                },{
                    typeId: 'd_Intended', // 类型(不能为空，且唯一，与组件中typeId值对应) --- 必填
                    typeNam: '', // 输入类型(number,text等) --- 选填
                    searchValMin: 'd_IntendedStartTimeMin', // 查询字段 --- 必填
                    // searchValMax: 'd_IntendedStartTimeMax', // 查询字段 --- 必填
                    defaultVal: '', // 字段默认值 --- 选填
                    placeholder: '计划动工开始日期', // placeholder数据
                    defaultProp: '', // 下拉框中使用，除下拉框外其它情况为空 --- 选填
                    eventType: '', // 事件类型（如burl/change等） --- 选填
                    defaultEvent: '', // 事件名称 --- 选填
                },{
                    typeId: 'd_Completion', // 类型(不能为空，且唯一，与组件中typeId值对应) --- 必填
                    typeNam: '', // 输入类型(number,text等) --- 选填
                    // searchValMin: 'd_IntendedCompletionTimeMin', // 查询字段 --- 必填
                    searchValMax: 'd_IntendedCompletionTimeMax', // 查询字段 --- 必填
                    defaultVal: '', // 字段默认值 --- 选填
                    placeholder: '计划完工日期', // placeholder数据
                    defaultProp: '', // 下拉框中使用，除下拉框外其它情况为空 --- 选填
                    eventType: '', // 事件类型（如burl/change等） --- 选填
                    defaultEvent: '', // 事件名称 --- 选填
                },{
                    typeId: 'i_Content', // 类型(不能为空，且唯一，与组件中typeId值对应) --- 必填
                    typeNam: '', // 输入类型(number,text等) --- 选填
                    searchVal: 'v_JobContent', // 查询字段 --- 必填
                    defaultVal: '', // 字段默认值 --- 选填
                    placeholder: '动工内容', // placeholder数据
                    defaultProp: '', // 下拉框中使用，除下拉框外其它情况为空 --- 选填
                    eventType: '', // 事件类型（如burl/change等） --- 选填
                    defaultEvent: '', // 事件名称 --- 选填
                },{
                    typeId: 's_Project', // 类型(不能为空，且唯一，与组件中typeId值对应) --- 必填
                    typeNam: '', // 输入类型(number,text等) --- 选填
                    searchVal: 'l_ProjectId', // 查询字段 --- 必填
                    defaultVal: '', // 字段默认值 --- 选填
                    placeholder: '项目', // placeholder数据
                    defaultProp: projectArr, // 下拉框中使用，除下拉框外其它情况为空 --- 选填
                    eventType: '', // 事件类型（如burl/change等） --- 选填
                    defaultEvent: '', // 事件名称 --- 选填
                },{
                    typeId: 'i_Apply', // 类型(不能为空，且唯一，与组件中typeId值对应) --- 必填
                    typeNam: '', // 输入类型(number,text等) --- 选填
                    searchVal: 'v_ApplyNO', // 查询字段 --- 必填
                    defaultVal: '', // 字段默认值 --- 选填
                    placeholder: '作业申请编号', // placeholder数据
                    defaultProp: '', // 下拉框中使用，除下拉框外其它情况为空 --- 选填
                    eventType: '', // 事件类型（如burl/change等） --- 选填
                    defaultEvent: '', // 事件名称 --- 选填
                },{
                    typeId: 's_Emp', // 类型(不能为空，且唯一，与组件中typeId值对应) --- 必填
                    typeNam: '', // 输入类型(number,text等) --- 选填
                    searchVal: 'l_ApplyEmpId', // 查询字段 --- 必填
                    defaultVal: '', // 字段默认值 --- 选填
                    placeholder: '申请人员', // placeholder数据
                    defaultProp: empArr, // 下拉框中使用，除下拉框外其它情况为空 --- 选填
                    eventType: '', // 事件类型（如burl/change等） --- 选填
                    defaultEvent: '', // 事件名称 --- 选填
                },{
                    typeId: 's_Dep', // 类型(不能为空，且唯一，与组件中typeId值对应) --- 必填
                    typeNam: '', // 输入类型(number,text等) --- 选填
                    searchVal: 'l_OrgId', // 查询字段 --- 必填
                    defaultVal: '', // 字段默认值 --- 选填
                    placeholder: '申请部门', // placeholder数据
                    defaultProp: depArr, // 下拉框中使用，除下拉框外其它情况为空 --- 选填
                    eventType: 'change', // 事件类型（如burl/change等） --- 选填
                    defaultEvent: 'depChange', // 事件名称 --- 选填
                    propsVal: { checkStrictly: true , label: 'title', value: 'id', children: 'children' }, // 级联选择器 --- 选填
                }
            ]
        }

        onBeforeMount(() => {
            searchObj.id = router.query.queryParam ? router.query.queryParam : null;
        });
        
        onMounted(async () => {
            // searchObj.id = router.query.queryParam ? router.query.queryParam : null;
            await getFun();
            await initInfoFun(); 
        });
        /*** ================================= 查询类数据操作 =================================  */

        /*** ================================= 导出数据函数操作 ================================= */
        const excelRef: any = ref(null);
        const handleExport = () => {
            if(excelRef){
                if(excelRef.value.data.length !== 0){
                    let tableExcel: any = [];
                    let tableArr = excelRef.value.data;
                    tableArr.map((item: any) => {
                        let tableObj: any = {};   
                        tableObj['作业申请编号'] = item.v_ApplyNO ? item.v_ApplyNO : '-';                  
                        tableObj['作业类型'] = item.v_JobType ? item.v_JobType : '-';
                        tableObj['承包商'] = item.v_ProviderName ? item.v_ProviderName : '-';
                        tableObj['风险分析单元'] = item.v_AnalysisUnitName ? item.v_AnalysisUnitName : '-';
                        tableObj['动工地点'] = item.v_JobAddress ? item.v_JobAddress : '-';
                        tableObj['开始日期'] = item.d_IntendedStartTime ? item.d_IntendedStartTime.split(' ')[0] : '-';
                        tableObj['完工日期'] = item.d_IntendedCompletionTime ? item.d_IntendedCompletionTime.split(' ')[0] : '-';
                        tableObj['动工内容'] = item.v_JobContent ? item.v_JobContent : '-';   
                        tableObj['项目名称'] = item.v_ProjectName ? item.v_ProjectName : '-';
                        tableObj['申请人员'] = item.v_ApplyEmpName ? item.v_ApplyEmpName : '-';
                        tableObj['审核流程状态'] = item.v_FlowinstanceStateName ? item.v_FlowinstanceStateName : '-';
                        tableExcel.push(tableObj);
                    });
                    exportToExcel(tableExcel,'作业活动申请.xlsx');
                }else{
                    ElMessage({
                        type: 'error',
                        message: '暂无数据导出',
                    })
                }
            }
        }
        /*** ================================= 导出数据函数操作 ================================= */

        return {
            ...getTableData(SMSJOBApplyPage,{},searchObj),

            repairInfo,
            isUseDialog,
            isHoldDialog,
            nodeClick,
            funClick,
            cancelUseClick,
            controlUseClick,
            deleteHandle,
            initInfo,
            initDialog,
            cancelInitClick,
            controlInitClick,
            exaUrl: SMSJOBApplyApplySubimt,
            // 文件上传
            documentClick,
            fileInfo,
            fileDialog,
            cancelFileClick,
            controlFileClick,
            // 作业票详情
            jobInfo,
            isJobDialog,
            cancelJobClick,
            detailHandle,

            // 导出Excel
            excelRef,
            handleExport,

            // 查询事件
            basicsInfo,
            searchHandel,
            searchClick,
            resetClick,
        }
    },
} )
</script>
<style lang="scss"> @import '../style/public.scss'; </style>
<style scoped lang="scss">
    ul {
        list-style: none;
        li {
            cursor: pointer;
            border-bottom: 1px solid rgba(255,255,255,0.1);
            text-align: center;
            padding: 10px 0;
        }
    }
    .search-s{
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 20px;
        width: 100%;
        .search-s-l{
            display: flex;
            flex-direction: row;
            justify-content: flex-start;
            align-items: center;
            width: 98%;
        }
    }
    #job-creat {
        .box-f{
            :deep(.el-form-item__label){
                padding: 0;
            }
        }
        :deep(.el-card__body) {
            height: 100%;
        }
        :deep(.el-card){
            border: none !important;
        }
        .upload-demo{
            margin-left: 12px;
            margin-top: 2px;
        }
        .icon-e{
            :deep(.el-icon){
                margin-right: 0px!important;
            }
        }
    }
.clear-bg{
    background-color: transparent !important;
}
</style>